package net.wang.totakecodenotes.wechatofficaccounts.controller.weixin;

import net.wang.totakecodenotes.wechatofficaccounts.utils.SignUtil;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 */
@RestController
@RequestMapping(value = "/sign")
public class SignController {

    private static final Logger logger = Logger.getLogger(SignController.class);

    @RequestMapping(value = "/signHandler", method = RequestMethod.GET)
    public Object serverTest(String signature,
                             String timestamp,
                             String nonce,
                             String echostr) {


        logger.info("signature = " + signature + "\ttimestamp = " + timestamp + "\tnonce = " + nonce);
        if (SignUtil.checkSignature(signature, timestamp, nonce)) {
            logger.info("请求成功");
            return echostr;
        } else {
            logger.info("非法请求");
        }
        return null;
    }


}
